home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / ofake.zoo / src / filesys.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-12  |  11.9 KB  |  383 lines

  1. /*
  2.  * NOTE: This file only works if sizeof(int) == 2!
  3.  * UNLESS: you have an ANSI compiler and use prototypes
  4.  *
  5.  * Copyright 1991 Eric R. Smith. This file may be re-distributed freely
  6.  * so long as this notice remains intact.
  7.  */
  8.  
  9. #ifndef _filesys_h
  10. #define _filesys_h
  11.  
  12. #ifndef P_
  13. # ifdef __STDC__
  14. #  define P_(x) x
  15. # else
  16. #  define P_(x) ()
  17. # endif
  18. #endif
  19.  
  20. #define NAME_MAX 32
  21. #define PATH_MAX 128
  22.  
  23. struct filesys;        /* forward declaration */
  24. struct devdrv;        /* ditto */
  25.  
  26. typedef struct f_cookie {
  27.     struct filesys *fs;    /* filesystem that knows about this cookie */
  28.     unsigned short    dev;        /* device info (e.g. Rwabs device number) */
  29.     unsigned short    aux;        /* extra data that the file system may want */
  30.     long    index;        /* this+dev uniquely identifies a file */
  31. } fcookie;
  32.  
  33. /* structure for opendir/readdir/closedir */
  34. typedef struct dirstruct {
  35.     fcookie fc;        /* cookie for this directory */
  36.     unsigned short    index;        /* index of the current entry */
  37.     unsigned short    flags;        /* flags (e.g. tos or not) */
  38. #define TOS_SEARCH    0x01
  39.     char    fsstuff[60];    /* anything else the file system wants */
  40.                 /* NOTE: this must be at least 45 bytes */
  41. } DIR;
  42.  
  43. /* structure for getxattr */
  44. typedef struct xattr {
  45.     unsigned short    mode;
  46. /* file types */
  47. #define S_IFMT    0170000        /* mask to select file type */
  48. #define S_IFCHR    0020000        /* BIOS special file */
  49. #define S_IFDIR    0040000        /* directory file */
  50. #define S_IFREG 0100000        /* regular file */
  51. #define S_IFIFO 0120000        /* FIFO */
  52. #define S_IMEM    0140000        /* memory region or process */
  53. #define S_IFLNK    0160000        /* symbolic link */
  54.  
  55. /* file access modes for user, group, and other*/
  56. #define S_IRUSR    0400
  57. #define S_IWUSR 0200
  58. #define S_IXUSR 0100
  59. #define S_IRGRP 0040
  60. #define S_IWGRP    0020
  61. #define S_IXGRP    0010
  62. #define S_IROTH    0004
  63. #define S_IWOTH    0002
  64. #define S_IXOTH    0001
  65. #define DEFAULT_DIRMODE (0777)
  66. #define DEFAULT_MODE    (0666)
  67.     long    index;
  68.     unsigned short    dev;
  69.     unsigned short    reserved1;
  70.     unsigned short    nlink;
  71.     unsigned short    uid;
  72.     unsigned short    gid;
  73.     long    size;
  74.     long    blksize, nblocks;
  75.     short    mtime, mdate;
  76.     short    atime, adate;
  77.     short    ctime, cdate;
  78.     short    attr;
  79.     short    reserved2;
  80.     long    reserved3[2];
  81. } XATTR;
  82.  
  83. typedef struct fileptr {
  84.     short    links;        /* number of copies of this descriptor */
  85.     unsigned short    flags;        /* file open mode and other file flags */
  86.     long    pos;        /* position in file */
  87.     long    devinfo;    /* device driver specific info */
  88.     fcookie    fc;        /* file system cookie for this file */
  89.     struct devdrv *dev; /* device driver that knows how to deal with this */
  90.     struct fileptr *next; /* link to next fileptr for this file */
  91. } FILEPTR;
  92.  
  93. typedef struct devdrv {
  94.     long (*open)    P_((FILEPTR *f));
  95.     long (*write)    P_((FILEPTR *f, char *buf, long bytes));
  96.     long (*read)    P_((FILEPTR *f, char *buf, long bytes));
  97.     long (*lseek)    P_((FILEPTR *f, long where, short whence));
  98.     long (*ioctl)    P_((FILEPTR *f, short mode, void *buf));
  99.     long (*datime)    P_((FILEPTR *f, short *timeptr, short rwflag));
  100.     long (*close)    P_((FILEPTR *f));
  101.     long (*select)    P_((FILEPTR *f, long proc, short mode));
  102.     void (*unselect) P_((FILEPTR *f, long proc, short mode));
  103. } DEVDRV;
  104.  
  105. typedef struct filesys {
  106.     struct    filesys    *next;    /* link to next file system on chain */
  107.     long    fsflags;
  108. #define FS_KNOPARSE    0x01    /* kernel shouldn't do parsing */
  109. #define FS_CASESENSITIVE    0x02    /* file names are case sensitive */
  110. #define FS_NOXBIT    0x04    /* if a file can be read, it can be executed */
  111.  
  112.     long    (*root) P_((short drv, fcookie *fc));
  113.     long    (*lookup) P_((fcookie *dir, char *name, fcookie *fc));
  114.     long    (*creat) P_((fcookie *dir, char *name, unsigned short mode,
  115.                 short attrib, fcookie *fc));
  116.     DEVDRV *(*getdev) P_((fcookie *fc, long *devspecial));
  117.     long    (*getxattr) P_((fcookie *fc, XATTR *xattr));
  118.     long    (*chattr) P_((fcookie *fc, short attr));
  119.     long    (*chown) P_((fcookie *fc, short uid, short gid));
  120.     long    (*chmode) P_((fcookie *fc, unsigned short mode));
  121.     long    (*mkdir) P_((fcookie *dir, char *name, unsigned short mode));
  122.     long    (*rmdir) P_((fcookie *dir, char *name));
  123.     long    (*remove) P_((fcookie *dir, char *name));
  124.     long    (*getname) P_((fcookie *relto, fcookie *dir, char *pathname));
  125.     long    (*rename) P_((fcookie *olddir, char *oldname,
  126.                 fcookie *newdir, char *newname));
  127.     long    (*opendir) P_((DIR *dirh, short tosflag));
  128.     long    (*readdir) P_((DIR *dirh, char *nm, short nmlen, fcookie *fc));
  129.     long    (*rewinddir) P_((DIR *dirh));
  130.     long    (*closedir) P_((DIR *dirh));
  131.     long    (*pathconf) P_((fcookie *dir, short which));
  132.     long    (*dfree) P_((fcookie *dir, long *buf));
  133.     long    (*writelabel) P_((fcookie *dir, char *name));
  134.     long    (*readlabel) P_((fcookie *dir, char *name, short namelen));
  135.     long    (*symlink) P_((fcookie *dir, char *name, char *to));
  136.     long    (*readlink) P_((fcookie *dir, char *buf, short len));
  137.     long    (*hardlink) P_((fcookie *fromdir, char *fromname,
  138.                 fcookie *todir, char *toname));
  139.     long    (*fscntl) P_((fcookie *dir, char *name, short cmd, long arg));
  140.     long    (*dskchng) P_((short drv));
  141.     long    zero;
  142. } FILESYS;
  143.  
  144. /*
  145.  * this is the structure passed to loaded file systems to tell them
  146.  * about the kernel
  147.  */
  148.  
  149. typedef long (*_LongFunc)();
  150.  
  151. struct kerinfo {
  152.     short    maj_version;    /* kernel version number */
  153.     short    min_version;    /* minor kernel version number */
  154.     unsigned short default_mode;    /* default file access mode */
  155.     short    reserved1;    /* room for expansion */
  156.  
  157. /* OS functions */
  158.     _LongFunc *bios_tab;     /* pointer to the BIOS entry points */
  159.     _LongFunc *dos_tab;    /* pointer to the GEMDOS entry points */
  160.  
  161. /* media change vector */
  162.     void    (*drvchng) P_((short));
  163.  
  164. /* Debugging stuff */
  165.     void    (*trace) P_((char *, ...));
  166.     void    (*debug) P_((char *, ...));
  167.     void    (*alert) P_((char *, ...));
  168.     void    (*fatal) P_((char *, ...));
  169.  
  170. /* memory allocation functions */
  171.     void *    (*kmalloc) P_((long));
  172.     void    (*kfree) P_((void *));
  173.     void *    (*umalloc) P_((long));
  174.     void    (*ufree) P_((void *));
  175.  
  176. /* utility functions for string manipulation */
  177.     short    (*strnicmp) P_((char *, char *, short));
  178.     short    (*stricmp) P_((char *, char *));
  179.     char *    (*strlwr) P_((char *));
  180.     char *    (*strupr) P_((char *));
  181.     short    (*sprintf) P_((char *, char *, ...));
  182.  
  183. /* utility functions for manipulating time */
  184.     void    (*millis_time) P_((unsigned long, short *));
  185.     long    (*unixtim) P_((unsigned short, unsigned short));
  186.     long    (*dostim) P_((long));
  187.  
  188. /* utility functions for dealing with pauses */
  189.     void    (*nap) P_((unsigned short));
  190.     void    (*sleep) P_((short que, long cond));
  191.     void    (*wake) P_((short que, long cond));
  192.     void    (*wakeselect) P_((long param));
  193.  
  194. /* file system utility functions */
  195.     short    (*denyshare) P_((FILEPTR *, FILEPTR *));
  196.  
  197. /* reserved for future use */
  198.     long    res2[10];
  199. };
  200.  
  201. /* flags for open() modes */
  202. #define O_RWMODE      0x03    /* isolates file read/write mode */
  203. #    define O_RDONLY    0x00
  204. #    define O_WRONLY    0x01
  205. #    define O_RDWR    0x02
  206. #    define O_EXEC    0x03    /* execute file; used by kernel only */
  207.  
  208. #define O_SHMODE    0x70    /* isolates file sharing mode */
  209. #    define O_COMPAT    0x00    /* compatibility mode */
  210. #    define O_DENYRW    0x10    /* deny both read and write access */
  211. #    define O_DENYW    0x20    /* deny write access to others */
  212. #    define O_DENYR    0x30    /* deny read access to others */
  213. #    define O_DENYNONE 0x40    /* don't deny any access to others */
  214.  
  215. #define O_NOINHERIT    0x80    /* this is currently ignored by MiNT */
  216.  
  217. #define O_NDELAY    0x100    /* don't block for i/o on this file */
  218. #define O_CREAT        0x200    /* create file if it doesn't exist */
  219. #define O_TRUNC        0x400    /* truncate file to 0 bytes if it does exist */
  220. #define O_EXCL        0x800    /* fail open if file exists */
  221.  
  222. #define O_USER        0x0fff    /* isolates user-settable flag bits */
  223.  
  224. /* kernel mode bits -- the user can't set these! */
  225. #define O_BIOS        0x2000
  226. #define O_HEAD        0x4000
  227. #define O_LOCK        0x8000
  228.  
  229. /* GEMDOS file attributes */
  230.  
  231. /* macros to be applied to FILEPTRS to determine their type */
  232. #define is_bios(f) (f->flags & O_BIOS)
  233.  
  234. /* lseek() origins */
  235. #define    SEEK_SET    0        /* from beginning of file */
  236. #define    SEEK_CUR    1        /* from current location */
  237. #define    SEEK_END    2        /* from end of file */
  238.  
  239. /* The requests for Dpathconf() */
  240. #define DP_IOPEN    0    /* internal limit on # of open files */
  241. #define DP_MAXLINKS    1    /* max number of hard links to a file */
  242. #define DP_PATHMAX    2    /* max path name length */
  243. #define DP_NAMEMAX    3    /* max length of an individual file name */
  244. #define DP_ATOMIC    4    /* # of bytes that can be written atomically */
  245. #define DP_TRUNC    5    /* file name truncation behavior */
  246. #    define    DP_NOTRUNC    0    /* long filenames give an error */
  247. #    define    DP_AUTOTRUNC    1    /* long filenames truncated */
  248. #    define    DP_DOSTRUNC    2    /* DOS truncation rules in effect */
  249.  
  250. #define DP_MAXREQ    5    /* highest legal request */
  251.  
  252. /* Dpathconf and Sysconf return this when a value is not limited
  253.    (or is limited only by available memory) */
  254.  
  255. #define UNLIMITED    0x7fffffffL
  256.  
  257. /* various character constants and defines for TTY's */
  258. #define MiNTEOF 0x0000ff1a    /* 1a == ^Z */
  259.  
  260. /* defines for tty_read */
  261. #define RAW    0
  262. #define COOKED    0x1
  263. #define NOECHO    0
  264. #define ECHO    0x2
  265.  
  266. /* constants for various Fcntl commands */
  267. /* constants for Fcntl calls */
  268. #define F_DUPFD        0        /* handled by kernel */
  269. #define F_GETFD        1        /* handled by kernel */
  270. #define F_SETFD        2        /* handled by kernel */
  271. #    define FD_CLOEXEC    1    /* close on exec flag */
  272.  
  273. #define F_GETFL        3        /* handled by kernel */
  274. #define F_SETFL        4        /* handled by kernel */
  275. #define F_GETLK        5
  276. #define F_SETLK        6
  277.  
  278. #define FSTAT        (('F'<< 8) | 0)    /* handled by kernel */
  279. #define FIONREAD    (('F'<< 8) | 1)
  280. #define FIONWRITE    (('F'<< 8) | 2)
  281. #define TIOCGETP    (('T'<< 8) | 0)
  282. #define TIOCSETP    (('T'<< 8) | 1)
  283. #define TIOCSETN    TIOCSETP
  284. #define TIOCGETC    (('T'<< 8) | 2)
  285. #define TIOCSETC    (('T'<< 8) | 3)
  286. #define TIOCGLTC    (('T'<< 8) | 4)
  287. #define TIOCSLTC    (('T'<< 8) | 5)
  288. #define TIOCGPGRP    (('T'<< 8) | 6)
  289. #define TIOCSPGRP    (('T'<< 8) | 7)
  290. #define TIOCFLUSH    (('T'<< 8) | 8)
  291. #define TIOCSTOP    (('T'<< 8) | 9)
  292. #define TIOCSTART    (('T'<< 8) | 10)
  293. #define TIOCGWINSZ    (('T'<< 8) | 11)
  294. #define TIOCSWINSZ    (('T'<< 8) | 12)
  295.  
  296. #define PPROCADDR    (('P'<< 8) | 1)
  297. #define PBASEADDR    (('P'<< 8) | 2)
  298.  
  299. /* terminal control constants */
  300. #define T_CRMOD        0x0001
  301. #define T_CBREAK    0x0002
  302. #define T_ECHO        0x0004
  303. #define T_RAW        0x0010
  304. #define T_TOS        0x0080
  305. #define T_TOSTOP    0x0100
  306.  
  307. /* the following are terminal status flags */
  308. #define TS_HOLD        0x1000        /* hold (e.g. ^S/^Q) */
  309. #define TS_COOKED    0x8000        /* interpret control chars */
  310.  
  311. /* structures for terminals */
  312. struct tchars {
  313.     char t_intrc;
  314.     char t_quitc;
  315.     char t_startc;
  316.     char t_stopc;
  317.     char t_eofc;
  318.     char t_brkc;
  319. };
  320.  
  321. struct ltchars {
  322.     char t_suspc;
  323.     char t_dsuspc;
  324.     char t_rprntc;
  325.     char t_flushc;
  326.     char t_werasc;
  327.     char t_lnextc;
  328. };
  329.  
  330. struct sgttyb {
  331.     char sg_ispeed;
  332.     char sg_ospeed;
  333.     char sg_erase;
  334.     char sg_kill;
  335.     unsigned short sg_flags;
  336. };
  337.  
  338. struct winsize {
  339.     short    ws_row;
  340.     short    ws_col;
  341.     short    ws_xpixel;
  342.     short    ws_ypixel;
  343. };
  344.  
  345. struct tty {
  346.     short        pgrp;        /* process group of terminal */
  347.     short        state;        /* terminal status, e.g. stopped */
  348.     short        use_cnt;    /* number of times terminal is open */
  349.     short        res1;        /* reserved for future expansion */
  350.     struct sgttyb     sg;
  351.     struct tchars     tc;
  352.     struct ltchars     ltc;
  353.     struct winsize    wsiz;
  354.     long        rsel;        /* selecting process for read */
  355.     long        wsel;        /* selecting process for write */
  356.     long        rsrvd[4];    /* reserved for future expansion */
  357. };
  358.  
  359. /* lock structure */
  360. struct flock {
  361.     short l_type;            /* type of lock */
  362. #define F_RDLCK        O_RDONLY
  363. #define F_WRLCK        O_WRONLY
  364. #define F_UNLCK        3
  365.     short l_whence;            /* SEEK_SET, SEEK_CUR, SEEK_END */
  366.     long l_start;            /* start of locked region */
  367.     long l_len;            /* length of locked region */
  368.     short l_pid;            /* pid of locking process
  369.                         (F_GETLK only) */
  370. };
  371.  
  372. /* defines for TOS attribute bytes */
  373. #ifndef FA_RDONLY
  374. #define           FA_RDONLY           0x01
  375. #define           FA_HIDDEN           0x02
  376. #define           FA_SYSTEM           0x04
  377. #define           FA_LABEL               0x08
  378. #define           FA_DIR               0x10
  379. #define           FA_CHANGED           0x20
  380. #endif
  381.  
  382. #endif _filesys_h
  383.